package com.kuaidi100.sdk.enums;

import com.ytjj.qmyx.supplychain.common.enums.CompanyEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * @author jiawei
 * @Description
 * @ClassName ExpressEnums
 **/
@Getter
@AllArgsConstructor
public enum ExpressEnums {
    COLLECT("1","揽收"),
    ORDERED("101","已下单"),
    PENDING_COLLECTION("102","待揽收"),
    TIMEOUT_PENDING_COLLECTION("1020","超时未揽收"),
    RECEIVED("103","已揽收"),
    IN_TRANSIT("0","在途"),
    ARRIVING_THE_CITY("1001","到达派件城市"),
    MAIN_LINE("1002","干线"),
    FORWARD("1003","转递"),
    DISPATCH("5","派件"),
    DELIVERY_COUNTER_OR_STATION("501","投柜或驿站"),
    SIGN_FOR("3","签收"),
    SIGNED_BY_MYSELF("301","本人签收"),
    SIGN_FOR_EXCEPTION("302","派件异常后签收"),
    SIGN_ON_BEHALF_OF("303","代签"),
    DELIVERY_OR_STATION_SIGNATURE("304","投柜或站签收"),
    RETURN_BACK("6","退回"),
    WITHDRAWAL("4","退签"),
    DESTROYED_ORDER("401","已销单"),
    TRANSFER("7","转投"),
    DIFFICULT("2","疑难"),
    OVERTIME_NOT_SIGNED_FOR("201","超时未签收"),
    TIMED_OUT_NOT_UPDATED("202","超时未更新"),
    REJECTION("203","拒收"),
    ABNORMAL_DELIVERY("204","派件异常"),
    TIMED_OUT_NOT_GET("205","柜或驿站超时未取"),
    UNABLE_TO_CONTACT("206","无法联系"),
    EXCEEDING_THE_AREA("207","超区"),
    RETENTION("208","滞留"),
    DAMAGE("209","破损"),
    DO_DESTROY_ORDER("210","销单"),
    CUSTOMS_CLEARANCE("8","清关"),
    WAITING_FOR_CUSTOMS_CLEARANCE("10","待清关"),
    IN_CUSTOMS_CLEARANCE("11","清关中"),
    CUSTOMS_CLEARED("12","已清关"),
    ABNORMAL_CUSTOMS_CLEARANCE("13","清关异常"),
    REFUSAL_TO_SIGN_FOR("14","拒签"),
    //下面是自定义状态
    NO_EXPRESS("-1","未录入快递单号"),
    NO_EXPRESS_DETAIL("-2","查无物流"),
    NO_EXPRESS_STATUS("-3","快递状态不存在"),
    DELIVERY_TIMEOUT("-4","超时未送达");

    /**
     * 状态编码
     */
    private String status;

    /**
     * 状态名称
     */
    private String statusName;


    /**
     * 获取物流高级状态文案
     */
    public static String getStatusName(String status){
        if(!StringUtils.isEmpty(status)){
            for (ExpressEnums value : ExpressEnums.values()) {
                if(status.equals(value.getStatus())){
                    return value.getStatusName();
                }
            }
        }
        return null;
    }

    /**
     * 获取异常状态名称
     * @param status
     * @return 有值则是异常状态，否则不为异常状态
     */
    public static String getExceptionName(String status){
        Map<String, String> map = getAllExpressException();
        String s = map.get(status);
        return s;
    }

    /**
     * 获取所有的异常枚举值
     */
    public static Map<String, String> getAllExpressException() {
        Map<String, String> map = new HashMap<>();
        //退回
        map.put(ExpressEnums.RETURN_BACK.getStatus(), ExpressEnums.RETURN_BACK.getStatusName());
        //拒签
        map.put(ExpressEnums.REFUSAL_TO_SIGN_FOR.getStatus(), ExpressEnums.REFUSAL_TO_SIGN_FOR.getStatusName());
        //退签
        map.put(ExpressEnums.WITHDRAWAL.getStatus(), ExpressEnums.WITHDRAWAL.getStatusName());
        //已销单
        map.put(ExpressEnums.DESTROYED_ORDER.getStatus(), ExpressEnums.DESTROYED_ORDER.getStatusName());
        //疑难
        map.put(ExpressEnums.DIFFICULT.getStatus(), ExpressEnums.DIFFICULT.getStatusName());
        //超时未签收
        map.put(ExpressEnums.OVERTIME_NOT_SIGNED_FOR.getStatus(), ExpressEnums.OVERTIME_NOT_SIGNED_FOR.getStatusName());
        //超时未更新
        map.put(ExpressEnums.TIMED_OUT_NOT_UPDATED.getStatus(), ExpressEnums.TIMED_OUT_NOT_UPDATED.getStatusName());
        //拒收
        map.put(ExpressEnums.REJECTION.getStatus(), ExpressEnums.REJECTION.getStatusName());
        //派件异常
        map.put(ExpressEnums.ABNORMAL_DELIVERY.getStatus(), ExpressEnums.ABNORMAL_DELIVERY.getStatusName());
        //柜或驿站超时未取
        map.put(ExpressEnums.TIMED_OUT_NOT_GET.getStatus(), ExpressEnums.TIMED_OUT_NOT_GET.getStatusName());
        //无法联系
        map.put(ExpressEnums.UNABLE_TO_CONTACT.getStatus(), ExpressEnums.UNABLE_TO_CONTACT.getStatusName());
        //超区
        map.put(ExpressEnums.EXCEEDING_THE_AREA.getStatus(), ExpressEnums.EXCEEDING_THE_AREA.getStatusName());
        //滞留
        map.put(ExpressEnums.RETENTION.getStatus(), ExpressEnums.RETENTION.getStatusName());
        //破损
        map.put(ExpressEnums.DAMAGE.getStatus(), ExpressEnums.DAMAGE.getStatusName());
        //销单
        map.put(ExpressEnums.DO_DESTROY_ORDER.getStatus(), ExpressEnums.DO_DESTROY_ORDER.getStatusName());
        //清关异常
        map.put(ExpressEnums.ABNORMAL_CUSTOMS_CLEARANCE.getStatus(), ExpressEnums.ABNORMAL_CUSTOMS_CLEARANCE.getStatusName());
        //转投
        map.put(ExpressEnums.TRANSFER.getStatus(), ExpressEnums.TRANSFER.getStatusName());
        //未录入快递单号
        map.put(ExpressEnums.NO_EXPRESS.getStatus(), ExpressEnums.NO_EXPRESS.getStatusName());
        //查无物流
        map.put(ExpressEnums.NO_EXPRESS_DETAIL.getStatus(), ExpressEnums.NO_EXPRESS_DETAIL.getStatusName());
        //超10天未送达
        map.put(ExpressEnums.DELIVERY_TIMEOUT.getStatus(), ExpressEnums.DELIVERY_TIMEOUT.getStatusName());
        //超时未揽收
        map.put(ExpressEnums.TIMEOUT_PENDING_COLLECTION.getStatus(), ExpressEnums.TIMEOUT_PENDING_COLLECTION.getStatusName());
        return map;
    }


    /**
     * 是否签收状态
     */
    public static boolean isCheck(String status) {
        Map<String,String> map = new HashMap<>();
        //签收
        map.put(ExpressEnums.SIGN_FOR.getStatus(),ExpressEnums.SIGN_FOR.getStatusName());
        //本人签收
        map.put(ExpressEnums.SIGNED_BY_MYSELF.getStatus(),ExpressEnums.SIGNED_BY_MYSELF.getStatusName());
        //派件异常后签收
        map.put(ExpressEnums.SIGN_FOR_EXCEPTION.getStatus(),ExpressEnums.SIGN_FOR_EXCEPTION.getStatusName());
        //代签
        map.put(ExpressEnums.SIGN_ON_BEHALF_OF.getStatus(),ExpressEnums.SIGN_ON_BEHALF_OF.getStatusName());
        //投柜或站签收
        map.put(ExpressEnums.DELIVERY_OR_STATION_SIGNATURE.getStatus(),ExpressEnums.DELIVERY_OR_STATION_SIGNATURE.getStatusName());
        if(null != map.get(status) && !"".equals(map.get(status))){
            return true;
        }
        return false;
    }

    /**
     * 所有揽收状态
     */
    public static String getCollectByStatus(String status){
        Map<String,String> map = new HashMap<>();
        //揽收
        map.put(ExpressEnums.COLLECT.getStatus(),ExpressEnums.COLLECT.getStatusName());
        //已下单
        map.put(ExpressEnums.ORDERED.getStatus(),ExpressEnums.ORDERED.getStatusName());
        //待揽收
        map.put(ExpressEnums.PENDING_COLLECTION.getStatus(),ExpressEnums.PENDING_COLLECTION.getStatusName());
        //已揽收
        map.put(ExpressEnums.RECEIVED.getStatus(),ExpressEnums.RECEIVED.getStatusName());
        String s = map.get(status);
        return s;
    }

    /**
     * 所有在途状态
     */
    public static String getAllInTransit(String status){
        Map<String,String> map = new HashMap<>();
        //在途
        map.put(ExpressEnums.IN_TRANSIT.getStatus(),ExpressEnums.IN_TRANSIT.getStatusName());
        //到达派件城市
        map.put(ExpressEnums.ARRIVING_THE_CITY.getStatus(),ExpressEnums.ARRIVING_THE_CITY.getStatusName());
        //干线
        map.put(ExpressEnums.MAIN_LINE.getStatus(),ExpressEnums.MAIN_LINE.getStatusName());
        //转递
        map.put(ExpressEnums.FORWARD.getStatus(),ExpressEnums.FORWARD.getStatusName());
        String s = map.get(status);
        return s;
    }

    /**
     * 所有用户拒收状态
     */
    public static String getRefundStatus(String status){
        Map<String,String> map = new HashMap<>();
        //退回
        map.put(ExpressEnums.RETURN_BACK.getStatus(),ExpressEnums.IN_TRANSIT.getStatusName());
        //退签
        map.put(ExpressEnums.WITHDRAWAL.getStatus(),ExpressEnums.ARRIVING_THE_CITY.getStatusName());
        //拒签
        map.put(ExpressEnums.REFUSAL_TO_SIGN_FOR.getStatus(),ExpressEnums.MAIN_LINE.getStatusName());
        //拒收
        map.put(ExpressEnums.REJECTION.getStatus(),ExpressEnums.FORWARD.getStatusName());
        String s = map.get(status);
        return s;
    }
}
